#include "ThreadPool.hpp"
#include "Task.hpp"
#include <unistd.h>
#include <time.h>

int main(/* int,char **,char ** */)
{
    srand((unsigned long)time(nullptr) ^ getpid());

    //ThreadPool<Task> *ptp=new ThreadPool<Task>();
    ThreadPool<Task> *ptp=ThreadPool<Task>::GetInstance();

    ptp->Run();

    while(true)
    {
        //生产的过程，制作任务的时候，要花时间
        int x = rand()%100 + 1;
        usleep(999);
        int y = rand()%30 + 1;

        Task t(x, y, [](int x, int y)->int{
            return x + y;
        });

        std::cout << "制作任务完成: " << x << "+" << y << "=?" << std::endl;

        // 推送任务到线程池中
        ptp->PushTask(t);

        usleep(9999);
    }

    return 0;
}